"""
用链表的方式在队列中实现这些步骤：
    初始化创建 Node, Queue 类
    依次添加 21 35 58 13 进队列
    返回队列头部元素
    删除此时队列头部元素
    返回此时队列头部元素
"""


class Node(object):
    def __init__(self, elem, next=None):
        self.elem = elem
        self.next = next


class Queue(object):
    def __init__(self):
        self.head = None
        self.rear = None

    def is_empty(self):
        return self.head is None

    def enqueue(self, elem):
        point = Node(elem)
        if self.is_empty():
            self.head = point
            self.rear = point
        else:
            self.rear.next = point
            self.rear = point

    def dequeue(self):
        if self.is_empty():
            print("Queue is Empty!")
        else:
            result = self.head.elem
            self.head = self.head.next
            return result

    def peek(self):
        if self.is_empty():
            print("Not Found")
        else:
            return self.head.elem

    def print_queue(self):
        print("queue: ")
        temp = self.head
        myqueue = []
        while temp is not None:
            myqueue.append(temp.elem)
            temp = temp.next
        print(myqueue)


if __name__ == '__main__':
    queue = Queue()
    queue.enqueue(21)
    queue.enqueue(35)
    queue.enqueue(58)
    queue.enqueue(13)
    queue.print_queue()
    print(queue.peek())
    queue.dequeue()
    queue.print_queue()
    print(queue.peek())






